<template>

  <div class="home-item">
    <div class='placeholder'
         v-if='item.placeholder'>
      <img v-lazy="require('@/assets/img-deft@2x.png')"
           alt="">
      <div class='text'>
        扫一扫赢大礼
      </div>
    </div>
    <!-- 正常销售商品 -->
    <div v-if='item.doorStatus==2'
         class='snuff'>

      <div class='top'
           @click='showDetail(item)'>
        <img v-lazy="
         item.picture"
             alt="产品图">
        <span :class="['theme_'+$store.state.styleColor]">{{item.alias}}</span>
        <div class='activity'>
          <img v-if="resData.isActivity&&_screen(item)&&!item.isLimit"
               src="@/assets/SUIJILJ.png"
               alt="随机立减">
          <img v-if=' item.isCash'
               src="@/assets/sphb@2x.png"
               class='
               hongbao'
               alt="红包大礼">
        </div>

      </div>
      <div class='middle'>
        {{item.productName}}
      </div>
      <div class='bottom'>
        <div>{{item.price }}
        </div>
        <div @click='buyGoods(item,_screen(item))'>
          <div :class="[_screen(item)?' ':'zhanpin']">

            <!-- <img v-if="_screen(item)"
                 src="@/assets/gwCar.png"
                 alt="购物车图片"> -->
            <span v-if="_screen(item)"
                  :class="['theme_'+$store.state.styleColor]">
              购买
            </span>
            <img v-else
                 src="@/assets/icon-zhanpin@2x.png"
                 alt="展品">
          </div>

        </div>

      </div>
    </div>
    <!--商品售空-->
    <div v-else-if='item.doorStatus==1'
         class='sell-out'
         :style="{'backgroundImage':'url('+require('@/assets/wawanlebg@2x.png')+')'}">

      <div class='top'>
        <span :class="['theme_'+$store.state.styleColor]">{{item.alias}}</span>
      </div>
      <div class='empty-text'>宝藏被挖空啦!</div>
    </div>
    <!-- 设备异常 -->
    <div v-else-if='item.doorStatus==3'
         class='yc-style'>
      <div class='top'>
        <img src="@/assets/img-gzkxcl@2x.png"
             alt="产品图">
        <span>{{item.alias}}</span>

      </div>
      <div class='middle'>
        格子开小差了
      </div>
      <div class='bottom'>
        <p class='not-goods-btn'>
          无货
        </p>
      </div>
    </div>
  </div>

</template>

<script>
// @ is an alias to /src

export default {
  props: {
    item: '',
    resData: {},
  },
  methods: {
    // 前三个判断 货柜机3以上是否有相同 用于显示随机立减图片，是否能购买
    // 柜子3以上的柜号卖空，方可提供购买。
    _screen (item) {
      // let resData = this.resData

      // let list = resData.vendorMainboardContainers[0].vendorDoorProucts
      // if (item.doorIndex <= 3) {
      //   for (let i = 3, len = list.length; i < len; i++) {
      //     const element = list[i];
      //     if (element.productId == item.productId && item.doorStatus != 1) {
      //       return false
      //     }
      //   }
      // }
      return true
    },
    buyGoods (item, state) {
      if (state) {
        this.$emit('change', item)
      }

    },
    showDetail (item) {

      this.$emit('show', item)
    }
  }


};
</script>
<style lang="scss">
@import "@/common/scss/mixin.scss";
// 编号
@mixin machinary-code() {
  position: absolute;
  top: 10px;
  left: 0;
  min-height: 45px;
  min-width: 45px;
  padding: 0 10px;
  border-radius: 8px;
  color: #fff;
  font-size: 26px; /*px*/
  @include fjc;
  box-sizing: border-box;
}

.home-item {
  min-width: 220px;
  max-width: 220px;
  box-sizing: border-box;
  background: #fff;
  // border-radius: 16px;
  padding: 0 20px;
  float: left;
  margin: 0 28px 64px 0;
  box-shadow: 0px 12px 8px rgba(185, 185, 185, 0.5);
  position: relative;
  z-index: 10;
  min-height: 334px;
  overflow: hidden;
  display: flex;
  align-self: stretch;
  
  .snuff {
    width: 100%;
    display: flex;
    align-content: space-between;
    flex-flow: row wrap;
  }
  .sell-out {
    position: absolute;
    top: 0;
    left: 0%;
    width: 100%;
    height: 100%;
    background: #f5f5f5;
    background-size: 100%;
    background-repeat: no-repeat;
    background-position: 0 -20px;
    .top {
      span {
        @include machinary-code;
        left: 10px;
      }
    }
    .empty-text {
      background: #f5f5f5;
      position: absolute;
      bottom: 0;
      left: 0;
      width: 100%;
      height: 75px;
      font-size: 24px; /*px*/
      @include fjc;
      color: #666;
    }
  }
  .yc-style {
    width: 100%;
    .top {
      padding-top: 50px;
      span {
        background: #979797;
      }
      img {
        width: 120px;
        height: 120px;
      }
    }
    .middle {
      padding-top: 6px;
    }
  }
  .top {
    width: 100%;
    padding: 20px 0;
    height: 220px;
    box-sizing: border-box;
    position: relative;
    @include fjc;

    img {
      height: 180px;
    }
    span {
      @include machinary-code;
      left: -10px;
    }
    .activity {
      position: absolute;
      top: 10px;
      right: -10px;
      img {
        display: block;
        width: 48px;
        height: auto;
        margin-bottom: 10px;
      }
      .hongbao {
        margin: auto;
        width: 40px;
      }
    }
  }
  .middle {
    @include color111;
    @include no-wrap;
    width: 100%;
    font-size: 26px; /*px*/
    margin-bottom: 15px;
  }
  .bottom {
    @include fjc(center, space-between);
    height: 68px;
    width: 100%;
    position: relative;
    @include border-top;

    > div:first-child {
      color: #e24a4a;
      font-size: 28px; /*px*/
      font-weight: 500;
      &::before {
        content: "￥";
        clear: both;
        font-weight: 700;
      }
    }
    > div:last-child {
      position: absolute;
      right: -25px;
      top: 50%;
      padding: 20px;
      transform: translate(0%, -50%);
      > div {
        border-radius: 100%;

        height: 44px;
        @include fjc;
        span {
          @include fjc;
          border-radius: 5px;
          font-size: 24px; /*px*/
          width: 80px;
          height: 44px;
          color: #ffff;
        }
        img {
          width: 78px;
        }
      }
    }
    .not-goods-btn {
      flex: 1;
      padding: 0;
    }
    .zhanpin {
      background: #fff !important;
      padding-right: 8px;
      img {
        width: 44px !important;
      }
    }
  }
}
.placeholder {
  position: relative;
  img {
    width: 100%;
  }
  .text {
    position: absolute;
    bottom: 0;
    width: 100%;
    height: 78px;
    font-size: 26px;
    font-weight: 700;
    color: #4a90e2;
    text-shadow: 0px 1px 0px #c0c0c0, 0px 2px 0px #b0b0b0, 0px 3px 0px #a0a0a0,
      0px 4px 0px #909090, 0px 5px 10px rgba(0, 0, 0, 0.4);
  }
}

 
</style>
